const Koa = require('koa');
const bodyParser = require('koa-bodyparser');
const KoaRouter = require('koa-router');
const koaStatic = require('koa-static');
const path = require('path');
const usersRouter = require('./routes/users');
const tasksRouter = require('./routes/tasks');

const app = new Koa();
const router = new KoaRouter();

// 提供 public 目录下的静态文件
app.use(koaStatic(path.join(__dirname, 'public')));

app.use(bodyParser());

router.get('/', async (ctx) => {
    ctx.redirect('/login.html'); 
});

router.use('/users', usersRouter.routes(), usersRouter.allowedMethods());
router.use('/tasks', tasksRouter.routes(), tasksRouter.allowedMethods());

app.use(router.routes());
app.use(router.allowedMethods());

app.listen(3000, () => {
    console.log('Server running on http://localhost:3000');
});
